package com.topInterview;

public class leecode162 {
    public int findPeekElement(int[] arr) {
        int N = arr.length;
        if (N < 2) {
            return 0;
        }

        if (arr[0] > arr[1]) {
            return 0;
        }
        if (arr[N - 1] > arr[N - 2]) {
            return N - 1;
        }

        int L = 1;
        int R = N - 2;
        int M = 0;
        while (L < R) {
            M = (L + R) / 2;
            if (arr[M - 1] < arr[M] && arr[M] > arr[M + 1]) {
                return M;
            } else if (arr[M - 1] > arr[M]) {
                R = M - 1;
            } else {
                L = M + 1;
            }
        }
        return L;


    }
}
